<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8" />
    <title>Document</title>
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <link rel="stylesheet" type="text/css" href="../css/mui.css"/>
</head>
<body>
	
	<header class="mui-bar mui-bar-nav">
	    <h1 class="mui-title">内地音乐</h1>
	</header>
	
	<div class="mui-content">
        <ul id="list" class="mui-table-view">
            
        </ul>
	</div>
	
	<!--放一个 audio -->
	<audio src="" id="myAudio"></audio>
	
	<!--创建一个模板-->
	<script type="text/html" id="tpl">
		{{each songlist}}
		<li class="mui-table-view-cell mui-media" data-url="{{$value['url']}}">
            <a href="javascript:;">
                <img class="mui-media-object mui-pull-left" src="{{$value['albumpic_small']}}">
                <div class="mui-media-body">
        			{{$value['songname']}}
                    <p class="mui-ellipsis">{{$value['singername']}}</p>
                </div>
            </a>
        </li>
        {{/each}}
	</script>
	
    
    <script src="../js/mui.js" type="text/javascript" charset="utf-8"></script>
    <script src="../js/template-web.js" type="text/javascript"></script>
    <script type="text/javascript">
	    mui.init();
	    
	    mui.get('http://route.showapi.com/213-4', {
	    	showapi_appid: 26444,
	    	showapi_sign: 'e6ed68d43d734b78892a649fedd90cbe',
	    	topid: 5
	    }, function(res) {
			if (res && res.showapi_res_code == 0) {
				// 获取前20条数据
				var songlist = res.showapi_res_body.pagebean.songlist.splice(0, 20);
				// 渲染模板
				var tpl = template('tpl', {songlist: songlist});
				document.querySelector('#list').innerHTML = tpl;
				
			} else {
				mui.alert(res.showapi_res_error);
			}
	    }, 'json');
	    
	    // 点击音乐列表进行放歌
	    mui('#list').on('tap', 'li', function() {
	    	var url = this.getAttribute('data-url');
	    	
	    	// 获取 audio对象
	    	var myAduio = document.querySelector('#myAudio');
	    	myAduio.src = url
	    	myAduio.play();
	    	
	    })
    </script>
</body>
</html>
